// pages/Main/mainIndex/mainIndex.js
var common = require('../../../utils/common.js')
var businessLogic = require('../../../utils/NetWork/Model/MainbusinessLogic.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    content: [],

    array: [],

  },
  bindPickerChange: function (e) {
    //console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
    this.collect();
    this.record();
    this.mistake();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = common.Getorgid();
    this.setData({
      orgid: c.orgid,
      userid: c.userid,
      index: 0,
    });
    this.mychild();
  },
  mychild: function () {
    //7.1
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "parentid,relationtype", "searchValue": '' + this.data.userid + ',0' }
    businessLogic.QueryTheirChildren(params, (res) => {
      //console.log("7.1", res)
      let child = new Array;
      for (let i = 0; i < res.length; i++) {
        child[i] = res[i].childid_peopleinfo_title;
      }
      //console.log(child);
      this.setData({
        array: child,
        content: res
      });
      this.collect();
      this.record();
      this.mistake();
    })
  },
  //6.3.1
  collect: function () {
    var i = this.data.index
    let param2 = { "userid": this.data.userid, "orgid": this.data.orgid, "searchField": "peopleid,iscollect", "searchValue": "" + this.data.content[i].childid + ",1" }
    businessLogic.ItemNumber(param2, (res) => {
     // console.log("6.3.1", res)
      this.setData({
        shoucang:res.length
      });
    })
  },
  //6.3.2查询人员记录
  record:function(){
    var i = this.data.index
    let param2 = { "userid": this.data.userid, "orgid": this.data.orgid, "searchField": "peopleid", "searchValue": "" + this.data.content[i].childid + "" }
    //console.log(param2)
    businessLogic.QueryRecords(param2, (res) => {
      //console.log("6.3.2", res)
      this.setData({
        jilu: res.length
      });
    })
  },
  //6.3.3查询错题数
  mistake: function () {
    var i = this.data.index
    let param2 = { "userid": this.data.userid, "orgid": this.data.orgid, "searchField": "peopleid,statemark,haspg", "searchValue": "" + this.data.content[i].childid + ",0,1" }
    //console.log(param2)
    businessLogic.WrongNumber(param2, (res) => {
      //console.log("6.3.3", res)
      this.setData({
        cuoti: res.length
      });
    })
  },
  mayTest: function () {
     wx.navigateTo({
      url: "../mayTest/mayTest?id=" + this.data.content[this.data.index].childid
    });  
   // console.log(this.data.content[this.data.index].childid)
  }, alreadytest: function () {
    wx.navigateTo({
      url: "../alreadytest/alreadytest?id=" + this.data.content[this.data.index].childid
    });
  }, misTopic: function () {
    wx.navigateTo({
      url: "../misTopic/misTopic?id=" + this.data.content[this.data.index].childid
    });
  },
  learnLog: function () {
    wx.navigateTo({
      url: "../learnLog/learnLog?id=" + this.data.content[this.data.index].childid
    });
  },
  todayJob: function () {
    wx.navigateTo({
      url: "../todayJob/todayJob?id=" + this.data.content[this.data.index].childid
    });
  },
  weaknowledge: function () {
    wx.navigateTo({
      url: "../weaknowledge/weaknowledge?id=" + this.data.content[this.data.index].childid
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})